package com.cy.pj.goods.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
//@ResponseBody
//@ControllerAdvice//次注解描述的类为全局异常处理类，在此类中可以定义多个异常处理方法
@RestControllerAdvice//ResponseBody+ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(IllegalArgumentException.class)
    @ResponseBody
    public String doHandleException(IllegalArgumentException e){
        log.error("IllegalArgumentException.exception{}",e.getMessage());
        return e.getMessage();
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public JsonResult doHandleRuntimeException(RuntimeException e){
        log.error("RuntimeException.exception{}",e.getMessage());
        return new JsonResult(e);
    }
    /*@ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public String doHandleRuntimeException(RuntimeException e){
        log.error("RuntimeException.exception{}",e.getMessage());
        return e.getMessage();
    }*/
}
